package edu.pucsp.predatorprey.tela;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import edu.pucsp.predatorprey.tela.observer.Observador;
import edu.pucsp.predatorprey.tela.util.CicloDeVida;
import edu.pucsp.predatorprey.tela.util.GridBagConstraintsBuilder;

public class PainelInformacoes extends JPanel implements Observador {

	private JLabel qtdPresasAtivas;

	private JLabel qtdPredadoresAtivos;

	private JLabel total;

	private final Modelo modelo;

	private JLabel numeroCiclo;

	public PainelInformacoes(Modelo modelo) {
		this.modelo = modelo;
		this.initComponents();
	}

	private void initComponents() {
		this.setLayout(new GridBagLayout());
		this.setBorder(BorderFactory.createTitledBorder("Info"));
		this.qtdPresasAtivas = new JLabel();
		this.qtdPredadoresAtivos = new JLabel();
		this.numeroCiclo = new JLabel();
		this.total = new JLabel();

		this.add(new JLabel("Número de coelhos:"),
				GridBagConstraintsBuilder.createContraint().anchor(GridBagConstraints.NORTHWEST).grid(0, 0).fill(GridBagConstraints.HORIZONTAL).build());
		this.add(this.qtdPresasAtivas,
				GridBagConstraintsBuilder.createContraint().grid(1, 0).weightx(1.0).anchor(GridBagConstraints.NORTHWEST).fill(GridBagConstraints.HORIZONTAL)
						.build());
		this.add(new JLabel("Número de raposas:"),
				GridBagConstraintsBuilder.createContraint().grid(0, 1).anchor(GridBagConstraints.NORTHWEST).fill(GridBagConstraints.HORIZONTAL).build());
		this.add(this.qtdPredadoresAtivos,
				GridBagConstraintsBuilder.createContraint().grid(1, 1).weightx(1.0).anchor(GridBagConstraints.NORTHWEST).fill(GridBagConstraints.HORIZONTAL)
						.build());
		this.add(new JLabel("Total Threads/Actors:"),
				GridBagConstraintsBuilder.createContraint().grid(0, 2).anchor(GridBagConstraints.NORTHWEST).fill(GridBagConstraints.HORIZONTAL).build());
		this.add(this.total,
				GridBagConstraintsBuilder.createContraint().grid(1, 2).weightx(1.0).anchor(GridBagConstraints.NORTHWEST).fill(GridBagConstraints.HORIZONTAL)
						.build());
		this.add(new JLabel("Ciclo:"),
				GridBagConstraintsBuilder.createContraint().grid(0, 3).anchor(GridBagConstraints.NORTHWEST).weighty(1.0).fill(GridBagConstraints.HORIZONTAL)
						.build());
		this.add(
				this.numeroCiclo,
				GridBagConstraintsBuilder.createContraint().grid(1, 3).weightx(1.0).anchor(GridBagConstraints.NORTHWEST).weighty(1.0)
						.fill(GridBagConstraints.HORIZONTAL).build());
	}

	@Override
	public void atualizar(CicloDeVida cicloDeVida) {
		if (cicloDeVida.equals(CicloDeVida.EXECUTANDO)) {
			this.qtdPresasAtivas.setText(String.valueOf(this.modelo.getQtdPresas()));
			this.qtdPredadoresAtivos.setText(String.valueOf(this.modelo.getQtdPredadores()));
			this.total.setText(String.valueOf(this.modelo.getNumeroDeExecucoesSimultaneas()));
			this.numeroCiclo.setText(String.valueOf(this.modelo.getCiclos()));
		}
	}

}
